package com.bm.tools.service.impl;

import com.bm.tools.service.IEmailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import java.util.Date;
@Service
@Slf4j
public class mailServiceImpl implements IEmailService {
    @Value("${spring.mail.username}")
    private String from;
    @Autowired
    private JavaMailSender javaMailSender;
    @Override
    public void sendEmail(String to, String subject, String content) {
        SimpleMailMessage smm=new SimpleMailMessage();
        smm.setSubject(subject);
        smm.setText(content);
        smm.setTo(to);
        smm.setFrom(from);
        smm.setSentDate(new Date());
        javaMailSender.send(smm);
        log.debug("发送邮件："+subject);
    }
}
